const mongoose = require('mongoose');

// 定义用户数据的 Schema（结构 + 校验）
const detailSchema = new mongoose.Schema({
    novelId: { 
        type: mongoose.Schema.Types.ObjectId, 
        ref: 'Novel',
        required: true
    },
    authorId: {
        type: mongoose.Schema.Types.ObjectId, 
        ref: 'User',
        required: true
    },
    title: { 
        type: String, 
        required:true,
    },
    chapterNum:{
        type: Number, 
        required:true
    },
    status: { 
        type: String, 
        enum:['草稿','发布','回收']
    },
    pub_date:{
        type: Date, 
        default: Date.now
    },
    content: { 
        type: String, 
        default:''
    },
    word_count: {
        type: Number,
        default: 0
    },
    read_time: { // 预估阅读时间（分钟）
        type: Number,
        default: 0
    }
});

// 创建并导出 Model（对应 MongoDB 的 "details" 集合）
const Detail = mongoose.model('Detail', detailSchema);

module.exports = Detail;